<template>
    <div class="home">
        <div class="card">
            <el-carousel :interval="4000" type="card" height="250px">
                <el-carousel-item
                    v-for="item in carouselList"
                    :key="item.imageUrl"
                >
                    <img :src="item.imageUrl" :alt="item.encodeId" />
                </el-carousel-item>
            </el-carousel>

            <div class="song_sheet">
                <div class="tag">
                    <h3>推荐歌单 ></h3>
                </div>
                <div class="song_sheet_card_list">
                    <div
                        class="song_sheet_card"
                        v-for="item in cardList"
                        :key="item.id"
                        @click="toMusiclistdetail(item.id)"
                    >
                        <img :src="item.picUrl" alt="" />
                        <p>{{ item.name }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import request from "@/request/request.js";
export default {
    data() {
        return {
            carouselList: [],
            cardList: []
        };
    },
    methods: {
        toMusiclistdetail(id) {
            this.$router.push(`/musiclistdetail/${id}`);
        }
    },
    created() {
        // 组件加载/创建执行
        request("/banner").then(res => {
            this.carouselList = res.data.banners;
        });
        request("/personalized?limit=10").then(res => {
            this.cardList = res.data.result;
        });
    }
};
</script>

<style lang="less" scoped>
.home {
    display: flex;
    justify-content: center;
    padding: 20px 200px 70px 200px;
    .card {
        width: 1000px;
        padding-top: 20px;
        .el-carousel {
            width: 1000px;
            margin: 0 auto;
        }
        .song_sheet {
            margin-top: 20px;
            text-align: start;
            .tag {
                padding-bottom: 20px;
            }
            .song_sheet_card_list {
                display: flex; // 弹性盒子布局 自动排列成一行
                flex-wrap: wrap; // 自动换行
                justify-content: space-between; // 两端分散对齐
                .song_sheet_card {
                    border-radius: 20px;
                    text-align: start;
                    width: 18%;
                    height: 18%;
                    padding-bottom: 30px;
                    cursor: pointer;
                    img {
                        border-radius: 10px;
                        width: 100%;
                        height: 100%;
                    }
                    p {
                        font-size: 16px;
                        font-weight: 700;
                    }
                }
            }
        }
    }
}
.el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
}
.el-carousel__item {
    border-radius: 20px;
    img {
        width: 100%;
        height: 100%;
    }
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
    background-color: #d3dce6;
}
</style>
